package vectortile.tile;

import com.google.protobuf.*;
import vectortile.layer.Layer;
import vectortile.layer.LayerOrBuilder;
import vectortile.model.VectorTile;

/**
 * @Author jlj
 * @Date 2020/12/28 11:51
 * @Description Protobuf type {@code vectortile.tile.Tile}
 * @Modified
 */
public final class Tile extends GeneratedMessageV3.ExtendableMessage<Tile> implements TileOrBuilder {
    private static final long serialVersionUID = 0L;

    // Use Tile.newBuilder() to construct.
    private Tile(GeneratedMessageV3.ExtendableBuilder<Tile, ?> builder) {
        super(builder);
    }

    private Tile() {
        layers_ = java.util.Collections.emptyList();
    }

    @java.lang.Override
    public final UnknownFieldSet
    getUnknownFields() {
        return this.unknownFields;
    }

    private Tile(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
        this();
        if (extensionRegistry == null) {
            throw new java.lang.NullPointerException();
        }
        int mutable_bitField0_ = 0;
        UnknownFieldSet.Builder unknownFields =
                UnknownFieldSet.newBuilder();
        try {
            boolean done = false;
            while (!done) {
                int tag = input.readTag();
                switch (tag) {
                    case 0:
                        done = true;
                        break;
                    case 26: {
                        if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
                            layers_ = new java.util.ArrayList<Layer>();
                            mutable_bitField0_ |= 0x00000001;
                        }
                        layers_.add(input.readMessage(Layer.PARSER, extensionRegistry));
                        break;
                    }
                    default: {
                        if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
                            done = true;
                        }
                        break;
                    }
                }
            }
        } catch (InvalidProtocolBufferException e) {
            throw e.setUnfinishedMessage(this);
        } catch (java.io.IOException e) {
            throw new InvalidProtocolBufferException(e).setUnfinishedMessage(this);
        } finally {
            if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
                layers_ = java.util.Collections.unmodifiableList(layers_);
            }
            this.unknownFields = unknownFields.build();
            makeExtensionsImmutable();
        }
    }

    public static final Descriptors.Descriptor getDescriptor() {
        return VectorTile.internal_static_vector_tile_Tile_descriptor;
    }

    @java.lang.Override
    protected GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() {
        return VectorTile.internal_static_vector_tile_Tile_fieldAccessorTable.ensureFieldAccessorsInitialized(Tile.class, Tile.Builder.class);
    }

    public static final int LAYERS_FIELD_NUMBER = 3;
    private java.util.List<Layer> layers_;

    /**
     * <code>repeated Layer layers = 3;</code>
     */
    public java.util.List<Layer> getLayersList() {
        return layers_;
    }

    /**
     * <code>repeated Layer layers = 3;</code>
     */
    public java.util.List<? extends LayerOrBuilder>
    getLayersOrBuilderList() {
        return layers_;
    }

    /**
     * <code>repeated Layer layers = 3;</code>
     */
    public int getLayersCount() {
        return layers_.size();
    }

    /**
     * <code>repeated Layer layers = 3;</code>
     */
    public Layer getLayers(int index) {
        return layers_.get(index);
    }

    /**
     * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
     */
    public LayerOrBuilder getLayersOrBuilder(int index) {
        return layers_.get(index);
    }

    private byte memoizedIsInitialized = -1;

    @java.lang.Override
    public final boolean isInitialized() {
        byte isInitialized = memoizedIsInitialized;
        if (isInitialized == 1) return true;
        if (isInitialized == 0) return false;

        for (int i = 0; i < getLayersCount(); i++) {
            if (!getLayers(i).isInitialized()) {
                memoizedIsInitialized = 0;
                return false;
            }
        }
        if (!extensionsAreInitialized()) {
            memoizedIsInitialized = 0;
            return false;
        }
        memoizedIsInitialized = 1;
        return true;
    }

    @java.lang.Override
    public void writeTo(CodedOutputStream output) throws java.io.IOException {
        GeneratedMessageV3.ExtendableMessage<Tile>.ExtensionWriter extensionWriter = newExtensionWriter();
        for (int i = 0; i < layers_.size(); i++) {
            output.writeMessage(3, layers_.get(i));
        }
        extensionWriter.writeUntil(8192, output);
        unknownFields.writeTo(output);
    }

    @java.lang.Override
    public int getSerializedSize() {
        int size = memoizedSize;
        if (size != -1) return size;

        size = 0;
        for (int i = 0; i < layers_.size(); i++) {
            size += CodedOutputStream.computeMessageSize(3, layers_.get(i));
        }
        size += extensionsSerializedSize();
        size += unknownFields.getSerializedSize();
        memoizedSize = size;
        return size;
    }

    @java.lang.Override
    public boolean equals(final java.lang.Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof Tile)) {
            return super.equals(obj);
        }
        Tile other = (Tile) obj;

        boolean result = true;
        result = result && getLayersList().equals(other.getLayersList());
        result = result && unknownFields.equals(other.unknownFields);
        result = result && getExtensionFields().equals(other.getExtensionFields());
        return result;
    }

    @java.lang.Override
    public int hashCode() {
        if (memoizedHashCode != 0) {
            return memoizedHashCode;
        }
        int hash = 41;
        hash = (19 * hash) + getDescriptor().hashCode();
        if (getLayersCount() > 0) {
            hash = (37 * hash) + LAYERS_FIELD_NUMBER;
            hash = (53 * hash) + getLayersList().hashCode();
        }
        hash = hashFields(hash, getExtensionFields());
        hash = (29 * hash) + unknownFields.hashCode();
        memoizedHashCode = hash;
        return hash;
    }

    public static Tile parseFrom(java.nio.ByteBuffer data) throws InvalidProtocolBufferException {
        return PARSER.parseFrom(data);
    }

    public static Tile parseFrom(java.nio.ByteBuffer data, ExtensionRegistryLite extensionRegistry)
            throws InvalidProtocolBufferException {
        return PARSER.parseFrom(data, extensionRegistry);
    }

    public static Tile parseFrom(ByteString data) throws InvalidProtocolBufferException {
        return PARSER.parseFrom(data);
    }

    public static Tile parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry)
            throws InvalidProtocolBufferException {
        return PARSER.parseFrom(data, extensionRegistry);
    }

    public static Tile parseFrom(byte[] data) throws InvalidProtocolBufferException {
        return PARSER.parseFrom(data);
    }

    public static Tile parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry)
            throws InvalidProtocolBufferException {
        return PARSER.parseFrom(data, extensionRegistry);
    }

    public static Tile parseFrom(java.io.InputStream input) throws java.io.IOException {
        return GeneratedMessageV3.parseWithIOException(PARSER, input);
    }

    public static Tile parseFrom(java.io.InputStream input, ExtensionRegistryLite extensionRegistry)
            throws java.io.IOException {
        return GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
    }

    public static Tile parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException {
        return GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input);
    }

    public static Tile parseDelimitedFrom(java.io.InputStream input, ExtensionRegistryLite extensionRegistry)
            throws java.io.IOException {
        return GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
    }

    public static Tile parseFrom(CodedInputStream input) throws java.io.IOException {
        return GeneratedMessageV3.parseWithIOException(PARSER, input);
    }

    public static Tile parseFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
            throws java.io.IOException {
        return GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry);
    }

    @java.lang.Override
    public Builder newBuilderForType() {
        return newBuilder();
    }

    public static Builder newBuilder() {
        return DEFAULT_INSTANCE.toBuilder();
    }

    public static Builder newBuilder(Tile prototype) {
        return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
    }

    @java.lang.Override
    public Builder toBuilder() {
        return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this);
    }

    @java.lang.Override
    protected Builder newBuilderForType(GeneratedMessageV3.BuilderParent parent) {
        Builder builder = new Builder(parent);
        return builder;
    }

    /**
     * Protobuf type {@code Tile}
     */
    public static final class Builder extends GeneratedMessageV3.ExtendableBuilder<Tile, Builder> implements TileOrBuilder {
        public static final Descriptors.Descriptor getDescriptor() {
            return VectorTile.internal_static_vector_tile_Tile_descriptor;
        }

        @java.lang.Override
        protected GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() {
            return VectorTile.internal_static_vector_tile_Tile_fieldAccessorTable.ensureFieldAccessorsInitialized(Tile.class, Tile.Builder.class);
        }

        // Construct using vector_tile.VectorTile.Tile.newBuilder()
        private Builder() {
            maybeForceBuilderInitialization();
        }

        private Builder(GeneratedMessageV3.BuilderParent parent) {
            super(parent);
            maybeForceBuilderInitialization();
        }

        private void maybeForceBuilderInitialization() {
            if (GeneratedMessageV3.alwaysUseFieldBuilders) {
                getLayersFieldBuilder();
            }
        }

        @java.lang.Override
        public Builder clear() {
            super.clear();
            if (layersBuilder_ == null) {
                layers_ = java.util.Collections.emptyList();
                bitField0_ = (bitField0_ & ~0x00000001);
            } else {
                layersBuilder_.clear();
            }
            return this;
        }

        @java.lang.Override
        public Descriptors.Descriptor getDescriptorForType() {
            return VectorTile.internal_static_vector_tile_Tile_descriptor;
        }

        @java.lang.Override
        public Tile getDefaultInstanceForType() {
            return Tile.getDefaultInstance();
        }

        @java.lang.Override
        public Tile build() {
            Tile result = buildPartial();
            if (!result.isInitialized()) {
                throw newUninitializedMessageException(result);
            }
            return result;
        }

        @java.lang.Override
        public Tile buildPartial() {
            Tile result = new Tile(this);
            int from_bitField0_ = bitField0_;
            if (layersBuilder_ == null) {
                if (((bitField0_ & 0x00000001) == 0x00000001)) {
                    layers_ = java.util.Collections.unmodifiableList(layers_);
                    bitField0_ = (bitField0_ & ~0x00000001);
                }
                result.layers_ = layers_;
            } else {
                result.layers_ = layersBuilder_.build();
            }
            onBuilt();
            return result;
        }

        @java.lang.Override
        public Builder clone() {
            return (Builder) super.clone();
        }

        @java.lang.Override
        public Builder setField(Descriptors.FieldDescriptor field, java.lang.Object value) {
            return (Builder) super.setField(field, value);
        }

        @java.lang.Override
        public Builder clearField(Descriptors.FieldDescriptor field) {
            return (Builder) super.clearField(field);
        }

        @java.lang.Override
        public Builder clearOneof(Descriptors.OneofDescriptor oneof) {
            return (Builder) super.clearOneof(oneof);
        }

        @java.lang.Override
        public Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, java.lang.Object value) {
            return (Builder) super.setRepeatedField(field, index, value);
        }

        @java.lang.Override
        public Builder addRepeatedField(Descriptors.FieldDescriptor field, java.lang.Object value) {
            return (Builder) super.addRepeatedField(field, value);
        }

        @java.lang.Override
        public <Type> Builder setExtension(GeneratedMessage.GeneratedExtension<Tile, Type> extension, Type value) {
            return (Builder) super.setExtension(extension, value);
        }

        @java.lang.Override
        public <Type> Builder setExtension(GeneratedMessage.GeneratedExtension<Tile, java.util.List<Type>> extension, int index, Type value) {
            return (Builder) super.setExtension(extension, index, value);
        }

        @java.lang.Override
        public <Type> Builder addExtension(GeneratedMessage.GeneratedExtension<Tile, java.util.List<Type>> extension, Type value) {
            return (Builder) super.addExtension(extension, value);
        }

        @java.lang.Override
        public <Type> Builder clearExtension(GeneratedMessage.GeneratedExtension<Tile, ?> extension) {
            return (Builder) super.clearExtension(extension);
        }

        @java.lang.Override
        public Builder mergeFrom(Message other) {
            if (other instanceof Tile) {
                return mergeFrom((Tile) other);
            } else {
                super.mergeFrom(other);
                return this;
            }
        }

        public Builder mergeFrom(Tile other) {
            if (other == Tile.getDefaultInstance()) return this;
            if (layersBuilder_ == null) {
                if (!other.layers_.isEmpty()) {
                    if (layers_.isEmpty()) {
                        layers_ = other.layers_;
                        bitField0_ = (bitField0_ & ~0x00000001);
                    } else {
                        ensureLayersIsMutable();
                        layers_.addAll(other.layers_);
                    }
                    onChanged();
                }
            } else {
                if (!other.layers_.isEmpty()) {
                    if (layersBuilder_.isEmpty()) {
                        layersBuilder_.dispose();
                        layersBuilder_ = null;
                        layers_ = other.layers_;
                        bitField0_ = (bitField0_ & ~0x00000001);
                        layersBuilder_ = GeneratedMessageV3.alwaysUseFieldBuilders ?
                                getLayersFieldBuilder() : null;
                    } else {
                        layersBuilder_.addAllMessages(other.layers_);
                    }
                }
            }
            this.mergeExtensionFields(other);
            this.mergeUnknownFields(other.unknownFields);
            onChanged();
            return this;
        }

        @java.lang.Override
        public final boolean isInitialized() {
            for (int i = 0; i < getLayersCount(); i++) {
                if (!getLayers(i).isInitialized()) {
                    return false;
                }
            }
            if (!extensionsAreInitialized()) {
                return false;
            }
            return true;
        }

        @java.lang.Override
        public Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
            Tile parsedMessage = null;
            try {
                parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
            } catch (InvalidProtocolBufferException e) {
                parsedMessage = (Tile) e.getUnfinishedMessage();
                throw e.unwrapIOException();
            } finally {
                if (parsedMessage != null) {
                    mergeFrom(parsedMessage);
                }
            }
            return this;
        }

        private int bitField0_;

        private java.util.List<Layer> layers_ = java.util.Collections.emptyList();

        private void ensureLayersIsMutable() {
            if (!((bitField0_ & 0x00000001) == 0x00000001)) {
                layers_ = new java.util.ArrayList<Layer>(layers_);
                bitField0_ |= 0x00000001;
            }
        }

        private RepeatedFieldBuilderV3<Layer, Layer.Builder, LayerOrBuilder> layersBuilder_;

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public java.util.List<Layer> getLayersList() {
            if (layersBuilder_ == null) {
                return java.util.Collections.unmodifiableList(layers_);
            } else {
                return layersBuilder_.getMessageList();
            }
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public int getLayersCount() {
            if (layersBuilder_ == null) {
                return layers_.size();
            } else {
                return layersBuilder_.getCount();
            }
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Layer getLayers(int index) {
            if (layersBuilder_ == null) {
                return layers_.get(index);
            } else {
                return layersBuilder_.getMessage(index);
            }
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder setLayers(int index, Layer value) {
            if (layersBuilder_ == null) {
                if (value == null) {
                    throw new NullPointerException();
                }
                ensureLayersIsMutable();
                layers_.set(index, value);
                onChanged();
            } else {
                layersBuilder_.setMessage(index, value);
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder setLayers(int index, Layer.Builder builderForValue) {
            if (layersBuilder_ == null) {
                ensureLayersIsMutable();
                layers_.set(index, builderForValue.build());
                onChanged();
            } else {
                layersBuilder_.setMessage(index, builderForValue.build());
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder addLayers(Layer value) {
            if (layersBuilder_ == null) {
                if (value == null) {
                    throw new NullPointerException();
                }
                ensureLayersIsMutable();
                layers_.add(value);
                onChanged();
            } else {
                layersBuilder_.addMessage(value);
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder addLayers(int index, Layer value) {
            if (layersBuilder_ == null) {
                if (value == null) {
                    throw new NullPointerException();
                }
                ensureLayersIsMutable();
                layers_.add(index, value);
                onChanged();
            } else {
                layersBuilder_.addMessage(index, value);
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder addLayers(Layer.Builder builderForValue) {
            if (layersBuilder_ == null) {
                ensureLayersIsMutable();
                layers_.add(builderForValue.build());
                onChanged();
            } else {
                layersBuilder_.addMessage(builderForValue.build());
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder addLayers(int index, Layer.Builder builderForValue) {
            if (layersBuilder_ == null) {
                ensureLayersIsMutable();
                layers_.add(index, builderForValue.build());
                onChanged();
            } else {
                layersBuilder_.addMessage(index, builderForValue.build());
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder addAllLayers(java.lang.Iterable<? extends Layer> values) {
            if (layersBuilder_ == null) {
                ensureLayersIsMutable();
                AbstractMessageLite.Builder.addAll(values, layers_);
                onChanged();
            } else {
                layersBuilder_.addAllMessages(values);
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder clearLayers() {
            if (layersBuilder_ == null) {
                layers_ = java.util.Collections.emptyList();
                bitField0_ = (bitField0_ & ~0x00000001);
                onChanged();
            } else {
                layersBuilder_.clear();
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Builder removeLayers(int index) {
            if (layersBuilder_ == null) {
                ensureLayersIsMutable();
                layers_.remove(index);
                onChanged();
            } else {
                layersBuilder_.remove(index);
            }
            return this;
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Layer.Builder getLayersBuilder(int index) {
            return getLayersFieldBuilder().getBuilder(index);
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public LayerOrBuilder getLayersOrBuilder(int index) {
            if (layersBuilder_ == null) {
                return layers_.get(index);
            } else {
                return layersBuilder_.getMessageOrBuilder(index);
            }
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public java.util.List<? extends LayerOrBuilder> getLayersOrBuilderList() {
            if (layersBuilder_ != null) {
                return layersBuilder_.getMessageOrBuilderList();
            } else {
                return java.util.Collections.unmodifiableList(layers_);
            }
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Layer.Builder addLayersBuilder() {
            return getLayersFieldBuilder().addBuilder(Layer.getDefaultInstance());
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public Layer.Builder addLayersBuilder(int index) {
            return getLayersFieldBuilder().addBuilder(index, Layer.getDefaultInstance());
        }

        /**
         * <code>repeated .vector_tile.Tile.Layer layers = 3;</code>
         */
        public java.util.List<Layer.Builder> getLayersBuilderList() {
            return getLayersFieldBuilder().getBuilderList();
        }

        private RepeatedFieldBuilderV3<Layer, Layer.Builder, LayerOrBuilder> getLayersFieldBuilder() {
            if (layersBuilder_ == null) {
                layersBuilder_ = new RepeatedFieldBuilderV3<Layer, Layer.Builder, LayerOrBuilder>(
                        layers_,
                        ((bitField0_ & 0x00000001) == 0x00000001),
                        getParentForChildren(),
                        isClean());
                layers_ = null;
            }
            return layersBuilder_;
        }

        @java.lang.Override
        public final Builder setUnknownFields(final UnknownFieldSet unknownFields) {
            return super.setUnknownFields(unknownFields);
        }

        @java.lang.Override
        public final Builder mergeUnknownFields(final UnknownFieldSet unknownFields) {
            return super.mergeUnknownFields(unknownFields);
        }
    }

    // @@protoc_insertion_point(class_scope:vector_tile.Tile)
    private static final Tile DEFAULT_INSTANCE;

    static {
        DEFAULT_INSTANCE = new Tile();
    }

    public static Tile getDefaultInstance() {
        return DEFAULT_INSTANCE;
    }

    @java.lang.Deprecated
    public static final Parser<Tile> PARSER = new AbstractParser<Tile>() {
        @java.lang.Override
        public Tile parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
                throws InvalidProtocolBufferException {
            return new Tile(input, extensionRegistry);
        }
    };

    public static Parser<Tile> parser() {
        return PARSER;
    }

    @java.lang.Override
    public Parser<Tile> getParserForType() {
        return PARSER;
    }

    @java.lang.Override
    public Tile getDefaultInstanceForType() {
        return DEFAULT_INSTANCE;
    }

}
